/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pokerhandcheck;

/**
 *
 * @author cbowman
 */

import java.util.*;
import java.io.*;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        String firstHand = new String("");
        String secondHand = new String("");
        try{
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

            System.out.print("Enter the first hand:  ");

            firstHand = in.readLine();

            System.out.print("\nEnter the second hand:  ");

            secondHand = in.readLine();
        }
        catch(Exception e){System.out.println("Oh no!");}

        StringTokenizer st1 = new StringTokenizer(firstHand);
        StringTokenizer st2 = new StringTokenizer(secondHand);
        String[] hand1 = new String[5];
        String[] hand2 = new String[5];
        int n = 0;
        while(st1.hasMoreTokens()){
            hand1[n] = st1.nextToken();
            n++;
        }
        n = 0;
        while(st2.hasMoreTokens()){
            hand2[n] = st2.nextToken();
            n++;
        }

        int l1 = hand1[0].length();
        int l2 = hand1[1].length();
        int l3 = hand1[2].length();
        int l4 = hand1[3].length();
        int l5 = hand1[4].length();

        int lh1 = hand2[0].length();
        int lh2 = hand2[1].length();
        int lh3 = hand2[2].length();
        int lh4 = hand2[3].length();
        int lh5 = hand2[4].length();

        int card_one_value = 0;
        int card_two_value = 0;
        int card_three_value = 0;
        int card_four_value = 0;
        int card_five_value = 0;

        int card_one_value2 = 0;
        int card_two_value2 = 0;
        int card_three_value2 = 0;
        int card_four_value2 = 0;
        int card_five_value2 = 0;

        Character c1 = new Character('a');
        Character c2 = new Character('a');
        Character c3 = new Character('a');
        Character c4 = new Character('a');
        Character c5 = new Character('a');

        Character ch1 = new Character('a');
        Character ch2 = new Character('a');
        Character ch3 = new Character('a');
        Character ch4 = new Character('a');
        Character ch5 = new Character('a');

        if(l1 == 2){
            card_one_value = Character.digit(hand1[0].charAt(0), 10);
            c1 = hand1[0].charAt(1);
        }
        if(l2 == 2){
            card_two_value = Character.digit(hand1[1].charAt(0), 10);
            c2 = hand1[1].charAt(1);
        }
        if(l3 == 2){
            card_three_value = Character.digit(hand1[2].charAt(0), 10);
            c3 = hand1[2].charAt(1);
        }
        if(l4 == 2){
            card_four_value = Character.digit(hand1[3].charAt(0), 10);
            c4 = hand1[3].charAt(1);
        }
        if(l5 == 2){
            card_five_value = Character.digit(hand1[4].charAt(0), 10);
            c5 = hand1[4].charAt(1);
        }

        if(l1 == 3){
            card_one_value = Integer.valueOf(hand1[0].substring(0,2), 10);
            c1 = hand1[0].charAt(2);
        }
        if(l2 == 3){
            card_two_value = Integer.valueOf(hand1[1].substring(0,2), 10);
            c2 = hand1[1].charAt(2);
        }
        if(l3 == 3){
            card_three_value = Integer.valueOf(hand1[2].substring(0,2), 10);
            c3 = hand1[2].charAt(2);
        }
        if(l4 == 3){
            card_four_value = Integer.valueOf(hand1[3].substring(0,2), 10);
            c4 = hand1[3].charAt(2);
        }
        if(l5 == 3){
            card_five_value = Integer.valueOf(hand1[4].substring(0,2), 10);
            c5 = hand1[4].charAt(2);
        }

        if(lh1 == 2){
            card_one_value2 = Character.digit(hand2[0].charAt(0), 10);
            ch1 = hand2[0].charAt(1);
        }
        if(lh2 == 2){
            card_two_value2 = Character.digit(hand2[1].charAt(0), 10);
            ch2 = hand2[1].charAt(1);
        }
        if(lh3 == 2){
            card_three_value2 = Character.digit(hand2[2].charAt(0), 10);
            ch3 = hand2[2].charAt(1);
        }
        if(lh4 == 2){
            card_four_value2 = Character.digit(hand2[3].charAt(0), 10);
            ch4 = hand2[3].charAt(1);
        }
        if(lh5 == 2){
            card_five_value2 = Character.digit(hand2[4].charAt(0), 10);
            ch5 = hand2[4].charAt(1);
        }

        if(lh1 == 3){
            card_one_value2 = Integer.valueOf(hand2[0].substring(0,2), 10);
            ch1 = hand2[0].charAt(2);
        }
        if(lh2 == 3){
            card_two_value2 = Integer.valueOf(hand2[1].substring(0,2), 10);
            ch2 = hand2[1].charAt(2);
        }
        if(lh3 == 3){
            card_three_value2 = Integer.valueOf(hand2[2].substring(0,2), 10);
            ch3 = hand2[2].charAt(2);
        }
        if(lh4 == 3){
            card_four_value2 = Integer.valueOf(hand2[3].substring(0,2), 10);
            ch4 = hand2[3].charAt(2);
        }
        if(lh5 == 3){
            card_five_value2 = Integer.valueOf(hand2[4].substring(0,2), 10);
            ch5 = hand2[4].charAt(2);
        }

        int card_one_suit = 0;
        int card_two_suit = 0;
        int card_three_suit = 0;
        int card_four_suit = 0;
        int card_five_suit = 0;

        int card_one_suit2 = 0;
        int card_two_suit2 = 0;
        int card_three_suit2 = 0;
        int card_four_suit2 = 0;
        int card_five_suit2 = 0;

        String Heart = new String("H");
        String Spade = new String("S");
        String Diamond = new String("D");
        String Club = new String("C");

        if(Heart.equals(c1.toString()))
            card_one_suit = 2;
        if(Spade.equals(c1.toString()))
            card_one_suit = 1;
        if(Diamond.equals(c1.toString()))
            card_one_suit = 3;
        if(Club.equals(c1.toString()))
            card_one_suit = 4;
        if(Heart.equals(c2.toString()))
            card_two_suit = 2;
        if(Spade.equals(c2.toString()))
            card_two_suit = 1;
        if(Diamond.equals(c2.toString()))
            card_two_suit = 3;
        if(Club.equals(c2.toString()))
            card_two_suit = 4;
        if(Heart.equals(c3.toString()))
            card_three_suit = 2;
        if(Spade.equals(c3.toString()))
            card_three_suit = 1;
        if(Diamond.equals(c3.toString()))
            card_three_suit = 3;
        if(Club.equals(c3.toString()))
            card_three_suit = 4;
        if(Heart.equals(c4.toString()))
            card_four_suit = 2;
        if(Spade.equals(c4.toString()))
            card_four_suit = 1;
        if(Diamond.equals(c4.toString()))
            card_four_suit = 3;
        if(Club.equals(c4.toString()))
            card_four_suit = 4;
        if(Heart.equals(c5.toString()))
            card_five_suit = 2;
        if(Spade.equals(c5.toString()))
            card_five_suit = 1;
        if(Diamond.equals(c5.toString()))
            card_five_suit = 3;
        if(Club.equals(c5.toString()))
            card_five_suit = 4;

        if(Heart.equals(ch1.toString()))
            card_one_suit2 = 2;
        if(Spade.equals(ch1.toString()))
            card_one_suit2 = 1;
        if(Diamond.equals(ch1.toString()))
            card_one_suit2 = 3;
        if(Club.equals(ch1.toString()))
            card_one_suit2 = 4;
        if(Heart.equals(ch2.toString()))
            card_two_suit2 = 2;
        if(Spade.equals(ch2.toString()))
            card_two_suit2 = 1;
        if(Diamond.equals(ch2.toString()))
            card_two_suit2 = 3;
        if(Club.equals(ch2.toString()))
            card_two_suit2 = 4;
        if(Heart.equals(ch3.toString()))
            card_three_suit2 = 2;
        if(Spade.equals(ch3.toString()))
            card_three_suit2 = 1;
        if(Diamond.equals(ch3.toString()))
            card_three_suit2 = 3;
        if(Club.equals(ch3.toString()))
            card_three_suit2 = 4;
        if(Heart.equals(ch4.toString()))
            card_four_suit2 = 2;
        if(Spade.equals(ch4.toString()))
            card_four_suit2 = 1;
        if(Diamond.equals(ch4.toString()))
            card_four_suit2 = 3;
        if(Club.equals(ch4.toString()))
            card_four_suit2 = 4;
        if(Heart.equals(ch5.toString()))
            card_five_suit2 = 2;
        if(Spade.equals(ch5.toString()))
            card_five_suit2 = 1;
        if(Diamond.equals(ch5.toString()))
            card_five_suit2 = 3;
        if(Club.equals(ch5.toString()))
            card_five_suit2 = 4;

        Card card1 = new Card(card_one_value, card_one_suit);
        Card card2 = new Card(card_two_value, card_two_suit);
        Card card3 = new Card(card_three_value, card_three_suit);
        Card card4 = new Card(card_four_value, card_four_suit);
        Card card5 = new Card(card_five_value, card_five_suit);

        Card card1h = new Card(card_one_value2, card_one_suit2);
        Card card2h = new Card(card_two_value2, card_two_suit2);
        Card card3h = new Card(card_three_value2, card_three_suit2);
        Card card4h = new Card(card_four_value2, card_four_suit2);
        Card card5h = new Card(card_five_value2, card_five_suit2);

        Hand hand_one = new Hand(card1, card2, card3, card4, card5);
        Hand hand_two = new Hand(card1h, card2h, card3h, card4h, card5h);
        System.out.println("\n" + hand_one.toString() + " vs. " + hand_two.toString());
        System.out.println("\n");
        System.out.print("Hand one: ");
        System.out.println("");
        hand_one.CheckHand();
        System.out.print("\n\nHand two: ");
        System.out.println("");
        hand_two.CheckHand();
        if(hand_one.rank > hand_two.rank){
            System.out.println("Hand one is the winner!");
        }
        if(hand_one.rank < hand_two.rank){
            System.out.println("Hand two is the winner!");
        }
        if(hand_one.rank == hand_two.rank){
            if(hand_one.primary > hand_two.primary)
                System.out.println("Hand one is the winner!");
            if(hand_one.primary < hand_two.primary)
                System.out.println("Hand two is the winner!");
        }
    }

}
